package com.yhj.wchat.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.yhj.wchat.entity.query.PageSize;
import com.yhj.wchat.mapper.QunMemberMapper;
import org.springframework.stereotype.Service;


import com.yhj.wchat.entity.query.QunMemberQuery;
import com.yhj.wchat.entity.po.QunMember;
import com.yhj.wchat.entity.vo.PaginationResultVO;
import com.yhj.wchat.entity.query.SimplePage;

import com.yhj.wchat.service.QunMemberService;
import com.yhj.wchat.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("qunMemberService")
public class QunMemberServiceImpl implements QunMemberService {

	@Resource
	private QunMemberMapper<QunMember, QunMemberQuery> qunMemberMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<QunMember> findListByParam(QunMemberQuery param) {
		return this.qunMemberMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(QunMemberQuery param) {
		return this.qunMemberMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<QunMember> findListByPage(QunMemberQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<QunMember> list = this.findListByParam(param);
		PaginationResultVO<QunMember> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(QunMember bean) {
		return this.qunMemberMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<QunMember> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.qunMemberMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<QunMember> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.qunMemberMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(QunMember bean, QunMemberQuery param) {
		StringTools.checkParam(param);
		return this.qunMemberMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(QunMemberQuery param) {
		StringTools.checkParam(param);
		return this.qunMemberMapper.deleteByParam(param);
	}

	/**
	 * 根据QunIdAndUserId获取对象
	 */
	@Override
	public QunMember getQunMemberByQunIdAndUserId(String qunId, String userId) {
		return this.qunMemberMapper.selectByQunIdAndUserId(qunId, userId);
	}

	/**
	 * 根据QunIdAndUserId修改
	 */
	@Override
	public Integer updateQunMemberByQunIdAndUserId(QunMember bean, String qunId, String userId) {
		return this.qunMemberMapper.updateByQunIdAndUserId(bean, qunId, userId);
	}

	/**
	 * 根据QunIdAndUserId删除
	 */
	@Override
	public Integer deleteQunMemberByQunIdAndUserId(String qunId, String userId) {
		return this.qunMemberMapper.deleteByQunIdAndUserId(qunId, userId);
	}
}